objx("objx.OQueue").requires("objx.class");

var OQueue = OClass({
	
	_q: null,
	pos: 0,
	length: 0,
	optimiseSize: 15,
	
	init: function() {
		this._q = [];
	},
	
	push: function(o) {
		this._q.push(o);
		this.length++;
		return this;
	},
	
	pop: function() {
		
		var pos = this.pos;
		var _q = this._q;
		var l = _q.length;
 		var o = _q[pos++];
		
		// should we trim down the queue?
        if (l > this.optimiseSize && pos * 2 >= l) {

            this._q = _q.slice(pos);
            this.pos = 0;

        } else {
			this.pos = pos;
		}
		
		this.length--;
		return o;
		
	}
	
});

OProvides("objx.OQueue");